//
//  ZHFPresentationController.swift
//  ZHFWB
//
//  Created by 张海峰 on 2017/2/28.
//  Copyright © 2017年 张海峰. All rights reserved.
//

import UIKit

class ZHFPresentationController: UIPresentationController {
    var presentedFrame: CGRect = CGRect.zero
    
    //MARK:- 懒加载属性
    fileprivate lazy var coverView: UIView = UIView()
    override func containerViewWillLayoutSubviews() {
        super.containerViewWillLayoutSubviews()
        //1.设置弹出View的尺寸
        presentedView?.frame = presentedFrame 
        //2. 添加蒙版
        setupCoverView()
    }
}
//MARK:- 设置UI界面相关
extension ZHFPresentationController
{
    fileprivate  func setupCoverView()  {
        //1. 添加蒙版(这样可以把它放在PopoverView之下)
        containerView?.insertSubview(coverView, at: 0)
        //2. 设置蒙版属性
        coverView.backgroundColor = UIColor.init(white: 0.0, alpha: 0.3)
        coverView.frame = containerView!.bounds
        //3. 添加手势
        let tapGes = UITapGestureRecognizer(target: self, action: #selector(coverViewClick))
        coverView.addGestureRecognizer(tapGes)
        
    }
}
extension ZHFPresentationController
{
    func  coverViewClick() {
        presentedViewController.dismiss(animated: true, completion: nil)
    }
}
